package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;

    @Override
    public int insertTbClueTrackRecord(ClueTrackRecordVo ctr) {
        ctr.setType("0");//固定线索
//        TbClue tbClue = new TbClue();
        TbClue tbClue = tbClueMapper.selectTbClueById(ctr.getClueId());
        tbClue.setSubject(ctr.getSubject());
        tbClue.setLevel(ctr.getLevel());
        tbClue.setName(ctr.getName());
        tbClue.setSex(ctr.getSex());
        tbClue.setWeixin(ctr.getWeixin());
        tbClue.setQq(ctr.getQq());
        tbClue.setAge(ctr.getAge());
        tbClueMapper.updateTbClue(tbClue);

        TbClueTrackRecord tctr = new TbClueTrackRecord();
        //对象拷贝工具，自动匹配对应的成员变量并且赋值；
        BeanUtils.copyBeanProp(tctr,ctr);
        tctr.setCreateBy(SecurityUtils.getUsername());
        Date now = DateUtils.getNowDate();
        tctr.setCreateTime(now);
        int row = tbClueTrackRecordMapper.insertTbClueTrackRecord(tctr);
        return row;
    }

    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecord(Long clueId) {
        List<TbClueTrackRecord> tbClueTrackRecords = tbClueTrackRecordMapper.selectTbClueTrackRecord(clueId);
        return tbClueTrackRecords;
    }
}
